<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
    //
    public static function getConfig($name,$group = '网站设置'){
        $data = \Cache::remember('setting'.$name.$group,'2',function()use($name,$group){
            return self::where('name',$name)->where('group',$group)->first();
        });
        return $data['value'];
    }
    public function getType(){
        return $this->get()->groupBy('group')->toArray();
    }
    public function getRelCol($post){
        foreach ($post as $k=>$v){
            if($k=='_token') continue;
            $value = explode('_',$k);
            if(count($value)>1){
                $where['name'] = $value[1];
                $where['group'] = $post[$value[0]]['group'];
                $flight = self::where($where)->first();
                    $flight1 = self::find($flight->id);
                    $flight1->value = $v;
                    $flight1->save();
            }
        }
    }
}
